
def listSplit(text, L):
    "split a text by list of literals"
    cursor = 0
    result = []
    for lit in L:
        location = text.find(lit, cursor)
        assert location>=cursor, "cannot find literal in string "+repr((lit, text[cursor:cursor+30]))
        llit = len(lit)
        chunk = text[cursor:location]
        result.append(chunk)
        cursor = location + llit
    chunk = text[cursor:]
    result.append(chunk)
    return result

def test(text=""" {{using title}}TITLE{{/using}} {{using summary}}SUMMARY{{/using}} WHATEVER  """,
         L = ["{{using", "title", "}}", "{{/using}}", "{{using", "summary", "}}", "{{/using}}"]
         ):
    r = listSplit(text, L)
    print "split", r
    assert r[3]=="TITLE"
    assert r[7]=="SUMMARY"

if __name__=="__main__":
    test()
